<?php
namespace App\Repositories\System;

use App\Exceptions\OrdinaryException;
use App\Repositories\BaseRepository;
use App\Models\Notice\Notice;

class NoticeRepository extends BaseRepository{

    public function model()
    {
        // TODO: Implement model() method.
        return Notice::class;
    }

    /**
     * 获取最新公告消息
     *
     * @author zx
     * @date 2019-01-30
     * @return Model|Array
     */
    public function noticeLists()
    {
        $res = $this->orderBy("id", "desc")->limit(6)->get();
        $lists = $res->toArray();
        foreach ($res as $key => $notice) {
            if ($notice->users) {
                $lists[$key]['nickname'] = $notice->users->nickname;
            } else {
                $lists[$key]['nickname'] = "系统";
            }
        }
        return $lists;
    }

    public function serialization(array $attributes)
    {
        // TODO: Implement serialization() method.
    }

}